package com.thinkit.bigdata.web.controller.audioSearch;

import com.thinkit.bigdata.core.util.es.ESUtil;
import com.thinkit.bigdata.web.model.result.HtmlResult;
import com.thinkit.bigdata.web.service.audioSearch.AudioSeaService;
import com.thinkit.bigdata.web.service.impl.audioSearch.AudioSearchPubMetImpl;
import org.apache.log4j.Logger;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * Created by hccl on 2018/9/18.
 */
@RestController
@RequestMapping("/audio-search")
public class AudioSearch {

    private static Logger logger = Logger.getLogger(AudioSearch.class);

    @Resource
    private AudioSeaService audioSeaService;

    @Resource
    private ESUtil esUtil;

    @RequestMapping(value = "/get-data-by-mes", method = RequestMethod.POST)
    public HtmlResult searchData(HttpServletRequest request) {
        String logTxt = "【音频检索方法】";
        logger.info(logTxt);
        String pageNum = request.getParameter("pageNum");//起始页
        String pageSize = request.getParameter("pageSize");//每页条数
        String sortName = request.getParameter("sortName");//录音流水
        String sortOrder = request.getParameter("sortOrder");//录音流水
        logger.info(logTxt + "pageNum = " + pageNum);
        logger.info(logTxt + "pageSize = " + pageSize);
        logger.info(logTxt + "sortName = " + sortName);
        logger.info(logTxt + "sortOrder = " + sortOrder);
        try {
            return audioSeaService.searchData(request);
        } catch (Exception e) {
            e.printStackTrace();
            return HtmlResult.failure("获取数据异常");
        }
    }

    @RequestMapping(value = "/export-data-mes", method = RequestMethod.POST)
    public void exportMyAss(HttpServletRequest request, HttpServletResponse response) {
        String logTxt = "【话单信息-导出】";
        logger.info(logTxt);
        try {
            BoolQueryBuilder boolQuery = audioSeaService.getQuery(logTxt, request);
            new AudioSearchPubMetImpl().exportMyAss(logTxt, request, response, boolQuery, esUtil);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
